package com.ruoyi.system.controller;

import java.util.List;
import java.util.UUID;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.StandardDb15W;
import com.ruoyi.system.service.IStandardDb15WService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * standardStructController
 * 
 * @author ruoyi
 * @date 2025-05-27
 */
@RestController
@RequestMapping("/system/standardStruct")
public class StandardDb15WController extends BaseController
{
    @Autowired
    private IStandardDb15WService standardDb15WService;

    /**
     * 查询standardStruct列表
     */
    @PreAuthorize("@ss.hasPermi('system:standardStruct:list')")
    @GetMapping("/list")
    public TableDataInfo list(StandardDb15W standardDb15W)
    {
        startPage();
        List<StandardDb15W> list = standardDb15WService.selectStandardDb15WList(standardDb15W);
        return getDataTable(list);
    }

    /**
     * 导出standardStruct列表
     */
    @PreAuthorize("@ss.hasPermi('system:standardStruct:export')")
    @Log(title = "standardStruct", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StandardDb15W standardDb15W)
    {
        List<StandardDb15W> list = standardDb15WService.selectStandardDb15WList(standardDb15W);
        ExcelUtil<StandardDb15W> util = new ExcelUtil<StandardDb15W>(StandardDb15W.class);
        util.exportExcel(response, list, "standardStruct数据");
    }

    /**
     * 获取standardStruct详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:standardStruct:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(standardDb15WService.selectStandardDb15WById(id));
    }

    /**
     * 获取standardStruct详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:standardStruct:query')")
    @GetMapping(value = "/getInfoStruct/{id}")
    public AjaxResult getInfoStruct(@PathVariable("id") String id)
    {
        return success(standardDb15WService.selectStandardDb15WByBId(id));
    }

    /**
     * 获取standardStruct详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:standardStruct:query')")
    @GetMapping(value = "/getStructTree/{id}")
    public AjaxResult getStructTree(@PathVariable("id") String id)
    {
        return standardDb15WService.selectStandardDb15WByBIdTree(id);
    }

    /**
     * 新增standardStruct
     */
//    @PreAuthorize("@ss.hasPermi('system:standardStruct:add')")
    @Log(title = "standardStruct", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StandardDb15W standardDb15W)
    {
        return toAjax(standardDb15WService.insertStandardDb15W(standardDb15W));
    }

    @Log(title = "standardStruct", businessType = BusinessType.INSERT)
    @PostMapping("/addList")
    public AjaxResult addList(@RequestBody List<StandardDb15W> standardDb15WList)
    {
        //先删除
        String bid = standardDb15WList.get(0).getbId();
        standardDb15WService.deleteStandardDb15WByBId(bid);
        for(StandardDb15W standardDb15W : standardDb15WList){
            String id = UUID.randomUUID().toString();
            standardDb15W.setId(id);
            standardDb15WService.insertStandardDb15W(standardDb15W);
        }
        return AjaxResult.success();
    }

    /**
     * 修改standardStruct
     */
    @PreAuthorize("@ss.hasPermi('system:standardStruct:edit')")
    @Log(title = "standardStruct", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StandardDb15W standardDb15W)
    {
        return toAjax(standardDb15WService.updateStandardDb15W(standardDb15W));
    }

    /**
     * 删除standardStruct
     */
    @PreAuthorize("@ss.hasPermi('system:standardStruct:remove')")
    @Log(title = "standardStruct", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(standardDb15WService.deleteStandardDb15WByIds(ids));
    }
}
